package lumis.service.portalmanagement.lock;

import lumis.doui.processaction.ProcessActionHandler;
import lumis.doui.source.Source;
import lumis.doui.source.field.ISourceField;
import lumis.portal.PortalException;
import lumis.portal.lock.LockManager;
import lumis.portal.manager.ManagerFactory;
import lumis.util.XmlUtil;

/**
 * {@link ProcessActionHandler} responsible for force unlockment of portal
 * locks.
 * 
 * @version $Revision: 11804 $ $Date: 2010-07-29 10:06:21 -0300 (Thu, 29 Jul 2010) $
 * @since 5.6.0
 */
public class LockProcessActionHandler extends ProcessActionHandler<Source<ISourceField>>
{
	private static final String PROCESS_FORCE_UNLOCK_ACTION = "forceUnlockAction";

	public void processAction() throws PortalException
	{
		String actionType = XmlUtil.readAttributeString("actionType", processActionNode);
		if (PROCESS_FORCE_UNLOCK_ACTION.equals(actionType))
			processForceUnlockAction();
	}

	private void processForceUnlockAction() throws PortalException
	{
		String[] resourceIds = getParameter("id", String[].class);
		if (resourceIds != null && resourceIds.length > 0)
		{
			for (String resourceId : resourceIds)
			{
				((LockManager) ManagerFactory.getLockManager()).forceUnlock(resourceId);
			}
		}

		addDefaultResponse();
	}
}